// assetAllocateApi.js

import request from '@/utils/request'

const baseUri = '/assetAllocate'

const assetAllocateApi = {
  // 获取资产分配列表
  list({ page, limit, ...others }) {
    return request({
      url: `${baseUri}/list`,
      method: 'get',
      params: {
        page,
        limit,
        ...others
      }
    })
  },

  // 根据ID获取资产分配信息
  find(id) {
    return request({
      url: `${baseUri}/find`,
      method: 'get',
      params: { id }
    })
  },

  // 获取所有资产分配信息
  findAll() {
    return request({
      url: `${baseUri}/findAll`,
      method: 'get'
    })
  },

  // 新增资产分配
  add(assetAllocate) {
    return request({
      url: `${baseUri}/add`, // 修正为正确的 URL
      method: 'post',
      data: assetAllocate
    })
  },

  // 更新资产分配
  update(assetAllocate) {
    return request({
      url: `${baseUri}/update`,
      method: 'post',
      data: assetAllocate
    })
  },

  // 批量新增资产分配
  batchAdd(assetAllocates) {
    return request({
      url: `${baseUri}/batchAdd`,
      method: 'post',
      data: assetAllocates // 将 AssetAllocate 数组作为请求体传递
    })
  },

  // 批量更新资产分配
  batchUpdate(assetAllocates) {
    return request({
      url: `${baseUri}/batchUpdate`,
      method: 'post',
      data: assetAllocates
    })
  },

  // 批量删除资产分配
  batchRemove(ids) {
    return request({
      url: `${baseUri}/batchRemove`,
      method: 'post',
      data: ids
    })
  },

  // 获取固定资产分配信息
  findAllocateFixed({ page, limit, ...others }) {
    return request({
      url: `${baseUri}/findAllocateFixed`,
      method: 'get',
      params: {
        page,
        limit,
        ...others
      }
    })
  },

  // 根据批量id查找固定资产
  addClaimFixedDetail({ page, limit, assetIds}) {
    return request({
      url: `${baseUri}/addAllocateFixedDetail`,
      method: 'post',
      data: {
        page,
        limit,
        assetIds
      }
    })
  },

  // 获取固定资产分配详情
  findAllocateFixedDetail({ page, limit, ...others }) {
    return request({
      url: `${baseUri}/findAllocateFixedDetail`,
      method: 'get',
      params: {
        page,
        limit,
        ...others
      }
    })
  },

  // 根据申请单号和assetId删除
  deleteByAssetIds({ applicationNum, assetIds}) {
    return request({
      url: `${baseUri}/deleteByAssetIds`,
      method: 'post',
      data: {
        applicationNum,
        assetIds
      }
    })
  },

  // 根据申请单号和assetId修改
  updateByAssetIds({ applicationNum, assetIds, allocate}) {
    return request({
      url: `${baseUri}/updateByAssetIds`,
      method: 'post',
      data: {
        applicationNum,
        assetIds,
        allocate
      }
    })
  },

  // 根据申请单号查询
  findByNum(applicationNum) {
    return request({
      url: `${baseUri}/findByNum`,
      method: 'get',
      params: {
        applicationNum
      }
    })
  }
}

export default assetAllocateApi
